export const settoken = token => uni.setStorageSync("token", token)

export const gettoken = () => uni.getStorageSync("token")

/**
 * 请求
 */
// export const httpRequest=(url,data={},method="GET")=>{
// 	return uni.request({
// 		url,
// 		data,
// 		method,
// 		header:{
// 			token:gettoken()
// 		}
// 	}).then(res=>res.data)
// }

const BASE_URL = "http://101.42.35.238:3006"



export function httpRequest(url, data = {}, method = "GET", loading = true, ) {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				token: gettoken() || ""
			},
			url: BASE_URL + url,
			method,
			data,
			async success(res) {
				resolve(res.data);
				if (res.data?.statusCode == 401) {
					uni.showToast({
						icon: "error",
						duration: 2000,
						title: res.data.errorMessage
					});
					settoken("")
				}

			},

		});
	});
};












/**
 * 处理图片地址
 */
export const dalImg = str => {
	if (str) {
		if (str.startsWith('http')) return str
		return 'http://101.42.35.238:3006' + str
	}
	return 'https://img1.baidu.com/it/u=3671217301,3239618685&fm=253&fmt=auto&app=138&f=JPEG?w=1422&h=800' // 默认图
}




/**
 * 时间处理
 */
export const getSimpleDate = date => {
		var y = date.getFullYear()
		var m = date.getMonth() + 1;
		m = m < 10 ? ('0' + m) : m;
		var d = date.getDate();
		d = d < 10 ? ('0' + d) : d;
		var h = date.getHours();
		var minute = date.getMinutes();
		minute = minute < 10 ? ('0' + minute) : minute;
		let time = y + '-' + m + '-' + d + ' ' + h + ':' + minute;
		return time
	}